<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>async延时函数</title>
</head>
<body>
    <script>
        async function sleep(delay = 2000){
            return new Promise((resolve,reject) => {
                setTimeout(() => {
                    // 这边不改变状态，程序就会一直等他改变状态才继续向下执行
                    resolve();
                },delay)
            })
        }

        async function show(){
            let user = ['xiaxia','xiasnn','hdr'];
            for (const value of user) {
                await sleep();
                console.log(value);
            }
        }

        show();
    </script>
</body>
</html>